<template>
  <div class="app-container">
    <!-- 优惠券活动信息 -->
    <div class="table-layout">
      <el-row>
        <el-col :span="4" class="table-cell-title">名称</el-col>
        <el-col :span="4" class="table-cell-title">优惠券类型</el-col>
        <el-col :span="4" class="table-cell-title">可使用商品</el-col>
        <el-col :span="4" class="table-cell-title">使用门槛</el-col>
        <el-col :span="4" class="table-cell-title">面值</el-col>
        <el-col :span="4" class="table-cell-title">状态</el-col>
      </el-row>
      <el-row>
        <el-col :span="4" class="table-cell">{{ couponActivity.activityName }}</el-col>
        <el-col :span="4" class="table-cell">{{ couponActivity.activityType }}</el-col>
        <el-col :span="4" class="table-cell">{{ couponActivity.useType }}</el-col>
        <el-col :span="4" class="table-cell">满{{ couponActivity.minPoint }}元可用</el-col>
        <el-col :span="4" class="table-cell">{{ couponActivity.amount }}元</el-col>
        <el-col :span="4" class="table-cell">{{ couponActivity.statis }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="4" class="table-cell-title">有效期</el-col>
        <el-col :span="4" class="table-cell-title">总发行量</el-col>
        <el-col :span="4" class="table-cell-title">已领取</el-col>
        <el-col :span="4" class="table-cell-title">待领取</el-col>
        <el-col :span="4" class="table-cell-title">已使用</el-col>
        <el-col :span="4" class="table-cell-title">未使用</el-col>
      </el-row>
      <el-row>
        <el-col :span="4" class="table-cell" style="font-size: 13px">
          {{ parseTime(couponActivity.startTime) }}至{{ parseTime(couponActivity.endTime) }}
        </el-col>
        <el-col :span="4" class="table-cell">{{ couponActivity.publishCount }}</el-col>
        <el-col :span="4" class="table-cell">{{ couponActivity.receiveCount }}</el-col>
        <el-col :span="4" class="table-cell">{{ couponActivity.publishCount-couponActivity.receiveCount }}</el-col>
        <el-col :span="4" class="table-cell">{{ couponActivity.useCount }}</el-col>
        <el-col :span="4" class="table-cell">{{ couponActivity.publishCount - couponActivity.useCount }}</el-col>
      </el-row>
    </div>

    <!-- 高级查询 -->
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search" />
        <span>筛选搜索</span>
        <el-button style="float:right" size="small" type="primary" @click="handleQuery">查询搜索</el-button>
        <el-button style="float:right;margin-right: 15px" size="small" @click="resetQuery">重置</el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true" :model="queryParams" size="small" label-width="140px">
          <el-form-item label="使用状态：">
            <el-select v-model="queryParams.useStatus" placeholder="全部" clearable class="input-width">
              <el-option v-for="item in options.useStatusOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="订单编号：">
            <el-input v-model="queryParams.salesOrderNo" class="input-width" placeholder="订单编号" />
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <!-- 数据列表 -->
    <div class="table-container">
      <el-table v-loading="loading" :data="page.records" highlight-current-row>
        <el-table-column label="优惠券编码" align="center" prop="couponCode" />
        <el-table-column label="活动名称" align="center" prop="activityId" />
        <el-table-column label="金额" align="center" prop="amount" />
        <el-table-column label="领取人" align="center" prop="receiver" />
        <el-table-column label="获取类型" align="center" prop="getType" />
        <el-table-column label="使用时间" align="center" prop="useTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.useTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单编号" align="center" prop="salesOrderNo" />
        <el-table-column label="状态" align="center" prop="status" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />
  </div>
</template>

<script>
import CouponApi from '@/api/marketing/CouponApi'
import CouponActivityApi from '@/api/marketing/CouponActivityApi'

export default {
  name: 'CouponList',
  data() {
    return {
      options: {
        useStatusOptions: []
      },
      activityId: null,
      couponActivity: {},
      queryParams: {
        activityId: null,
        useStatus: null,
        salesOrderNo: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.activityId = this.$route.query.activityId
    this.queryParams.activityId = this.$route.query.activityId
    this.getCoupon()
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    getCoupon() {
      CouponActivityApi.get(this.activityId).then(response => {
        this.couponActivity = response.data
      })
    },
    handleQuery() {
      this.loading = true
      CouponApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
<style scoped>
  .app-container {
    width: 80%;
    margin: 20px auto;
  }

  .filter-container {
    margin-top: 20px;
  }

  .table-layout {
    margin-top: 20px;
    border-left: 1px solid #DCDFE6;
    border-top: 1px solid #DCDFE6;
  }

  .table-cell {
    height: 60px;
    line-height: 40px;
    border-right: 1px solid #DCDFE6;
    border-bottom: 1px solid #DCDFE6;
    padding: 10px;
    font-size: 14px;
    color: #606266;
    text-align: center;
    overflow: hidden;
  }

  .table-cell-title {
    border-right: 1px solid #DCDFE6;
    border-bottom: 1px solid #DCDFE6;
    padding: 10px;
    background: #F2F6FC;
    text-align: center;
    font-size: 14px;
    color: #303133;
  }
</style>
